//
// Created by Administrator on 2020/9/21.
//

#include "stun.h"

uint64_t ntoh64(const uint64_t& input)
{
    uint64_t rval = 0;
    uint8_t *data = (uint8_t *)&rval;

    data[0] = (uint8_t)((input >> 56) & 0xFF);
    data[1] = (uint8_t)((input >> 48) & 0xFF);
    data[2] = (uint8_t)((input >> 40) & 0xFF);
    data[3] = (uint8_t)((input >> 32) & 0xFF);
    data[4] = (uint8_t)((input >> 24) & 0xFF);
    data[5] = (uint8_t)((input >> 16) & 0xFF);
    data[6] = (uint8_t)((input >> 8) & 0xFF);
    data[7] = (uint8_t)((input >> 0) & 0xFF);

    return rval;
}

uint32_t ntoh32(const uint32_t& input)
{
    uint32_t rval = 0;
    uint8_t *data = (uint8_t *)&rval;

    data[0] = (uint8_t)((input >> 24) & 0xFF);
    data[1] = (uint8_t)((input >> 16) & 0xFF);
    data[2] = (uint8_t)((input >> 8) & 0xFF);
    data[3] = (uint8_t)((input >> 0) & 0xFF);
    return rval;
}

uint16_t ntoh16(const uint16_t& input)
{
    uint16_t rval = 0;
    uint8_t *data = (uint8_t *)&rval;

    data[0] = (uint8_t)((input >> 8) & 0xFF);
    data[1] = (uint8_t)((input >> 0) & 0xFF);
    return rval;
}